<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>轮播图</title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
                list-style: none;
            }
            div{
                overflow: hidden;
                width: 910px;
                margin: 30px auto;
                position: relative;
                cursor: pointer;
            }
            ul{
                width: 3000px;
                transition: 1s;
            }
            ul li img{
                width: 910px;
            }
            ul li{
                float: left;
            }
            ol{
                bottom: 10px;
                left: 50%;
                transform: translateX(-50%);
                position: absolute;
            }
            ol li{
                cursor: pointer;
                width: 15px;
                height: 15px;
                background-color: #999;
                border-radius: 50%;
                float: left;
                margin: 0 4px;
            }
            .current{
                background-color: #444;
            }
            .left{
                position: absolute;
                left: 25px;
                text-align: center;
                width: 30px;
                height: 70px;
                line-height: 70px;
                background-color: rgba(68, 68, 68, 0.322);
                top: 50%;
                transform: translateY(-50%);
            }
            .right{
                position: absolute;
                right: 25px;
                text-align: center;
                width: 30px;
                height: 70px;
                line-height: 70px;
                background-color: rgba(68, 68, 68, 0.322);
                top: 50%;
                transform: translateY(-50%);
            }
        </style>
    </head>
    <body>
        <div id="wrsp">
            <ul id="box">
                <li>
                    <img src="images/s001.jpg" alt="">
                </li>
                <li>
                    <img src="images/s002.jpg" alt="">
                </li>
                <li>
                    <img src="images/s003.jpg" alt="">
                </li>
            </ul>
            <ol id="list">
                <li class="current"></li>
                <li></li>
                <li></li>
            </ol>
            <div id="left" class="left"><</div>
            <div id="right" class="right">></div>
        </div>

        <script>
            var wrsp=document.getElementById('wrsp');
            var box=document.getElementById('box');
            var list=document.getElementById('list').children;
            var left=document.getElementById('left');
            var right=document.getElementById('right');
            var num=0;
            var timer;

            function move(){
                box.style.transform="translate("+(-910*num)+"px)";
            }

            function imgMove(){
                num++;
                if(num>2){
                    num=0;
                }
                move();
                index();
            }

            function index(){
                for(var i=0;i<list.length;i++){
                    list[i].className='';
                }
                list[num].className='current';
            }


            for(var i=0;i<list.length;i++){
                list[i].tag=i;
                list[i].onclick=function(){
                    for(var j=0;j<list.length;j++){
                        list[j].className='';
                    }
                    this.className='current';
                    var k=this.tag;
                    box.style.transform="translate("+(-910*k)+"px)";
                }
            }

            left.onclick=function(){
                num--;
                if(num<0){
                    num=2;
                }
                index();
                move();
            }

            right.onclick=function(){
                num++;
                if(num>2){
                    num=0;
                }
                index();
                move();
            }

            timer=setInterval(imgMove,2000);
            wrsp.onmouseenter=function(){
                clearInterval(timer);
            }
            wrsp.onmouseleave=function(){
                timer=setInterval(imgMove,2000);
            }
        </script>
    </body>
</html>